﻿using Application.MainModule.RateParamTypeManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.RateParamTypes;
using Domain.MainModule.Entities;
using System.Collections.Generic;
using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for RateParamManagementServiceTest and is intended
    ///to contain all RateParamManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RateParamManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddRateParam
        ///</summary>
        [TestMethod()]
        public void AddRateParam_Invoke_Test()
        {
            //Arrange
            IRateParamTypeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateParamTypeManagementService>();
            Guid rateParamTypeId = Guid.NewGuid();
            RateParamType rateParam = new RateParamType()
            {
                TypeId = rateParamTypeId,                
            };

            //Act
            target.AddRateParamType(rateParam);
            RateParamType result = target.FindRateParamTypeById(rateParamTypeId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(rateParam, result);
            target.RemoveRateParamType(result);
        }

        /// <summary>
        ///A test for ChangeRateParam
        ///</summary>
        [TestMethod()]
        public void ChangeRateParam_Invoke_Test()
        {
            //Arrange
            IRateParamTypeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateParamTypeManagementService>();
            Guid rateParamTypeId = Guid.Parse("ABCDF456-1234-1111-2222-AAAACCBBBBBB");
 
            //Act
            RateParamType rateParam = target.FindRateParamTypeById(rateParamTypeId);
            rateParam.Name = "new name";
            target.ChangeRateParamType(rateParam);
            RateParamType result = target.FindRateParamTypeById(rateParamTypeId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreNotEqual("name 01", result.Name);
        }

		/// <summary>
        ///A test for FindRateParamById
        ///</summary>
        [TestMethod()]
        public void FindRateParamById_Invoke_Test()
        {
            //Arrange
            IRateParamTypeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateParamTypeManagementService>();
            Guid rateParamId = Guid.Parse("ABCDF456-1234-3333-4444-AAAACCBBBBBB");

            //Act 
            RateParamType rateParam = target.FindRateParamTypeById(rateParamId);

            //Assert
            Assert.IsNotNull(rateParam);
            Assert.AreEqual(rateParamId, rateParam.TypeId);
        }
		
        /// <summary>
        ///A test for FindRateParamByName
        ///</summary>
        [TestMethod()]
        public void FindRateParamByName_Invoke_Test()
        {
            //Arrange
            IRateParamTypeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateParamTypeManagementService>();
            string name = "name 02";

            //Act
            List<RateParamType> actual;
            actual = target.FindRateParamTypesByName(name);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(name, actual[0].Name);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RemoveRateParam_Invoke_NullItemThrowNewArgumentNullException_Test()
        {
            //Arrange
            IRateParamTypeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateParamTypeManagementService>();

            //Act
            target.RemoveRateParamType(null);
        }

        /// <summary>
        ///A test for RemoveRateParam
        ///</summary>
        [TestMethod()]
        public void RemoveRateParam_Invoke_Test()
        {
            //Arrange
            IRateParamTypeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateParamTypeManagementService>();
            RateParamType rateParam = null;

            //Act
            rateParam = target.FindRateParamTypeById(Guid.Parse("ABCDF456-1234-1111-2222-AAAACCBBBBBB"));
            target.RemoveRateParamType(rateParam);

            //Assert
            RateParamType result = target.FindRateParamTypeById(Guid.Parse("ABCDF456-1234-1111-2222-AAAACCBBBBBB"));
            Assert.IsNull(result);
            rateParam = new RateParamType()
            {
                TypeId = Guid.Parse("ABCDF456-1234-1111-2222-AAAACCBBBBBB"),
                Name = "name 01"
            };
            target.AddRateParamType(rateParam);
        }
    }
}
